import requests
from eroica import xpath
from eroica import url_add
from tqdm import tqdm
import time

lift_time = time.time()
url = 'https://ssr1.scrape.center/'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
}

ses = requests.session()
response = ses.get(url=url, headers=headers)
response.encoding = 'utf-8'
html = response.text

xpath_str = '//*[@id="index"]/div[1]//*/div/div[1]/a/@href'

urls = url_add(url,xpath(html, xpath_str))
i = 0
for path in tqdm(urls):
    html = ses.get(url=path, headers=headers)
    xpaths = {
        'title': '//*[@id="detail"]/div[1]/div/div/div[1]/div/div[2]/a/h2/text()',
        'author': '//*[@id="detail"]/div[1]/div/div/div[1]/div/div[3]/p[1]/text()',
        'content': '//*[@id="detail"]/div[2]/div/div/div/div/div/p/text()'
    }
    print(xpath(html, xpaths))
    i += 1
    if i == 10:
        break
right_time = time.time()
print('耗时:', right_time - lift_time)


